<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta http-equiv="pragma" content="no-cache" />
		<title>民意征集</title>
		<%@ include file="../../../common/Admin-list.jsp"%>  
		<script type="text/javascript" src="<%=bpath %>Scripts/common/common.js"></script>
		<link rel="stylesheet" type="text/css" href="<%=basePath %>Themes/default/css/jquery.datetimepicker.css"/>    
		<script type="text/javascript" src="<%=basePath %>Scripts/jquery/jquery.datetimepicker.js"></script>
	
		
		<script type="text/javascript">
		$(function(){	
			
			//民意征集
			$('#dataGridSolicit').datagrid({		
				height:'480',
				width:'680',
				rownumbers:true,//设置为true将显示行数					
				striped:true, //设置为true将交替显示行背景
				fitColumns:true,//设置为true将自动使列适应表格宽度以防止出现水平滚动
				animate:true,
				collapsible:true,
				idField:'id',//id字段
				pagination : true,//分页控件
				pageSize : 10,
			    pageList : [10, 20, 30],
			    url : '../solicitPublicController/list.json',
				loadMsg : '数据装载中......',
				singleSelect : true,//设置为 true，则只允许选中一行					
				columns:[[					          	
							{field:'id',hidden:true,editor:{type:'text'}},
							{field:'title',title:'标题',width:100,align:'left',editor:{type:'text'},
								formatter:function(value,row,index){									
									var url="/SiteIndex/solicitView.htm?id="+encode64((row.id).toString())+'&muid=51&preview=yes';
									return '<a href="<%=basePath %>'+url+'" target="_blank" ><img src="<%=basePath %>pages/Admin/Images/search.gif" title="点击预览" style="margin-bottom:-3px"> &nbsp;</a>'+value;				   
								}
							},
							{field:'startDate',title:'开始时间',width:40,align:'center',editor:{type:'text'},
								formatter:function(value,row,index){  
	                        		var unixTimestamp = new Date(value);  
	                        		return unixTimestamp.format("yyyy-MM-dd"); 
	                        	}	
							},
							{field:'endDate',title:'结束时间',width:40,align:'center',editor:{type:'text'},
								formatter:function(value,row,index){  
	                        		var unixTimestamp = new Date(value);  
	                        		return unixTimestamp.format("yyyy-MM-dd"); 
	                        	}
							},
							{field:'status',title:'状态',width:40,align:'center',editor:{type:'text'},
								formatter:function(value,row,index){  
									if(row.visible==1){										
										if(row.startDate>new Date(GetDateStr(0))){
											return "<font color=\"##abce17\">等待生效</font>";											
										}else if(row.endDate>=new Date(GetDateStr(0))){
											return "<font color=\"blue\">征集中</font>";	
										}else if(row.endDate<new Date(GetDateStr(0))){
											return "<font color=\"#999\">征集结束</font>";	
										}
									}else{
										return "<font color=\"##abce17\">等待生效</font>";	
									}				                        		
	                        	}
							},
							{field:'totality',title:'参与人数',width:20,align:'left',editor:{type:'text'}},
							{field:'visible',title:'显示',width:20,align:'center',editor:{type:'text'},
								 formatter:function(value,row,index){	
						    		 if(value){
						    			 return '<span disabled="disabled"><input type="checkbox" checked="checked" disabled="disabled"></span> ';
						    		 }else{
						    			 return '';
						    		 }
							     }
							},							
							{field:'opt',title:'操作',width:100,align:'center',  
			                    formatter:function(value,rec,index){
			                    	
			                    	var edit='<a title="编辑" onclick="editSolicit(\''+ rec.id + '\')"  href="#">'+
			                    			'<img src="<%=basePath %>pages/Admin/Images/Icon/edit.gif" alt="Edit"></a>&nbsp;&nbsp;&nbsp;&nbsp;';
			                    	
			                        var dele='<a title="删除" onclick="delSolicit(\''+ rec.id +'\')"  href="#">'+
			                        		'<img src="<%=basePath %>pages/Admin/Images/Icon/delete.gif" alt="Delete"></a>&nbsp;&nbsp;';				                        
			                        
			                        var cog='<a title="查看评论" onclick="seeComment(\''+ rec.id +'\',\''+rec.title+'\')"  href="#">'+
			                        		'<img src="<%=basePath %>pages/Admin/Images/Icon/comment.gif" alt="Delete">评论</a>&nbsp;&nbsp;';				                        
			                       
			                        var addUser='<a title="意见采纳" onclick="addRemark(\''+ rec.id +'\')"  href="#">'+
			                        		'<img src="<%=basePath %>pages/Admin/Images/Icon/reset.gif" alt="Delete">采纳说明</a>&nbsp;&nbsp;';				                        
			                                              
			                        return edit+dele+cog+addUser;  
			                    }  
			                 }								
				        ]]	
			});			
			
			//加载评论			
			$('#dataGridComment').datagrid({		
				height:'455',
				width:'660',
				rownumbers:true,//设置为true将显示行数					
				striped:true, //设置为true将交替显示行背景
				fitColumns:true,//设置为true将自动使列适应表格宽度以防止出现水平滚动
				animate:true,
				collapsible:true,								
				idField:'id',//id字段	
				pagination : true,//分页控件
				pageSize : 10,
			    pageList : [10, 20, 30],
			    url : null,
				loadMsg : '数据装载中......',
				singleSelect : false,//设置为 true，则只允许选中一行		 {field:'ck',checkbox:true },		
				columns:[[	
							{field:'id',hidden:true,editor:{type:'text'}},
							{field:'fk_spid',hidden:true,editor:{type:'text'}},
							{field:'typeId',title:'参与方式',align:'center',editor:{type:'text'},
								formatter:function(value,row,index){  
									if(value==0){	
										return "<font color=\"#999\">点赞</font>";	
									}else{
										return "<font>评论</font>";	
									}				                        		
	                        	}
							},
							{field:'ip',title:'IP',width:60,align:'center',editor:{type:'text'}},
							{field:'contents',title:'评论内容',width:100,align:'left',editor:{type:'text'}},
							{field:'createTime',title:'评论时间',width:100,align:'center',editor:{type:'text'},
								formatter:function(value,row,index){  
	                        		var unixTimestamp = new Date(value);  
	                        		return unixTimestamp.format("yyyy-MM-dd hh:mm:ss"); 
	                        	}
							},	
							{field:'is_publish',title:'是否公开',width:40,align:'center',editor:{type:'text'},
								formatter:function(value,row,index){  
									if(value==1){	
										return "√";	
									}else{
										return " ";	
									}				                        		
	                        	}
							},													
							{field:'is_deleted',hidden:true,title:'组织架构ID',width:100,align:'center',editor:{type:'text'}},
							{field:'opt',title:'操作',width:60,align:'center',  
			                    formatter:function(value,rec,index){			                    	
			                    	var edit='<a title="查看" onclick="editComment(\''+ rec.id + '\')"  href="#">'+
			                    			'<img src="<%=basePath %>pages/Admin/Images/Icon/edit.gif" alt="Edit"></a>&nbsp;&nbsp;';
			                    			
			                        var dele='<a title="删除" onclick="delComment(\''+ rec.id +'\')"  href="#">'+
			                        		'<img src="<%=basePath %>pages/Admin/Images/Icon/delete.gif" alt="Delete"></a>&nbsp;&nbsp;';
			                        if(rec.typeId==0){
			                        	edit="";
			                        }
			                        
			                        return edit+dele;  
			                    }  
			                 }
						]],			    
	          
			});							
			
						
		}); // 结束页面加载
		
		// 搜索民意征集
		function searchSolicitList() {
			var queryParams = $('#dataGridSolicit').datagrid('options').queryParams;
			
			queryParams.title = $('#title').val();			
			if($('#visible').is(':checked')) {
				queryParams.visible =$('#visible').val();//是否显示
			}else{
				delete queryParams.visible;
			}
			
			var status = $('#status').val();
			if(status=="1"){ //等待
				queryParams.startDate=GetDateStr(1); // 开始时间大于 now
				delete queryParams.endDate;				
			}else if(status=="2"){// 征集中
				queryParams.endDateOver=GetDateStr(0); //结束时间大于 now	
				queryParams.visible="1";
				delete queryParams.startDate;
				delete queryParams.endDate;
			}else if(status=="3"){ //已结结束
				queryParams.endDate=GetDateStr(-1); // 结束时间小于 now
				delete queryParams.startDate;				
			}else{
				delete queryParams.startDate;
				delete queryParams.endDate;
			}						
			$('#dataGridSolicit').datagrid('reload');			
		}
		
		//获取时间
		function GetDateStr(AddDayCount) {
	        var dd = new Date();
	        dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期	       
	        var mon = dd.getMonth()+1;//获取当前月份的日期
	        var day = dd.getDate();
	        var str = dd.getFullYear()+"-"+(mon<10 ? "0"+ mon : mon)+"-"+(day<10?"0"+day:day);	        
	        return str;
	    }
	    	    
		
		function addSolicit(){  //新增民意征集 
			art.dialog.open('../solicitPublicController/addInterface.htm?type=add',{
				title: '',
				lock:true,
			  	width: '98%',
			    height: '98%'												   												   
			});
      	}
		
		function editSolicit(index){  //编辑  民意征集
			art.dialog.open('../solicitPublicController/updateInterface.htm?type=edit&id='+index,{
				title: '',
				lock:true,
			  	width: '98%',
			    height: '98%'												   												   
			});
      	}		
		
		function addRemark(index){  //意见 采纳说明
			art.dialog.open('../solicitPublicController/remarkInterface.htm?type=edit&id='+index,{
				title: '',
				lock:true,
			  	width: '68%',
			    height: '68%'												   												   
			});
      	}
		
		
		
		function delSolicit(index){  //删除操作
			art.dialog({
				icon: 'question',	
				width:250,
			    content: '你确定删除该数据？',
			    ok: function () {				    	
			    	$.ajax({
						type:'POST',
						dataType:'json',
						async:false,
						url:'../solicitPublicController/delete.json',
						data:{ids:index,delSub:true},
						success:function(data){
							if(data.success=true){									
								art.dialog({id : 'Tip',title : '消息',fixed : true,lock : true,opacity: .2,
        							content : '删除成功！',icon : 'succeed',time : 1  
        					    }); 
								window.location.reload();  
								
							}else{
								art.dialog.alert('删除失败，请联系管理员！');
							}
						}
					});
					
			    },
			    cancelVal: '取消',
			    cancel: true 
			});				
      	}
		
		
		// 搜索 评论
 		function searchSolicitComment() {
			var queryParams = $('#dataGridComment').datagrid('options').queryParams;
			
			queryParams.contents = $('#contents').val();	
			
			if($('#is_publish').is(':checked')) {
				queryParams.is_publish =$('#is_publish').val();//是否显示
			}else{
				delete queryParams.is_publish;
			}	
			
			var typeId = $('#typeId').val();			
			if(typeId==""){			
				delete queryParams.typeId;				
			}else {
				queryParams.typeId=typeId; 				
			}		
			
			$('#dataGridComment').datagrid('reload');			
		}
		
		//查看评论
		function seeComment(fk_spid,title){  		
			$('#roleGetComment').css('display','block');			
			$('#roleType').val(fk_spid);
			$('.notes').html("现在查看<strong>["+title+"]</strong>的评论列表！&nbsp;&nbsp;共有<strong>[<span id=\"totalComment\"></span>]</strong>人参与");				
			//加载评论
			$('#dataGridComment').datagrid({					
			    url : '../solicitPublicCommentController/list.json?fk_spid='+fk_spid,
			    onLoadSuccess:function(data){
			    	$("#totalComment").text(data.total);			    	
                }
			    
			});	
			
			
			
      	}
		
		function editComment(index){  //编辑 评论
			art.dialog.open('../solicitPublicCommentController/updateInterface.htm?type=edit&id='+index,{
				id:"testComment",
				title: '',
				lock:true,
			  	width: '68%',
			    height: '68%'												   												   
			});
      	}		
		
		function delComment(index){  //删除评论
			art.dialog({
				icon: 'question',	
				width:250,
			    content: '你确定删除该数据？',
			    ok: function () {				    	
			    	$.ajax({
						type:'POST',
						dataType:'json',
						async:false,
						url:'../solicitPublicCommentController/delete.json',
						data:{ids:index,delSub:true},
						success:function(data){
							if(data.success=true){									
								art.dialog({id : 'Tip',title : '消息',fixed : true,lock : true,opacity: .2,
        							content : '删除成功！',icon : 'succeed',time : 1  
        					    }); 
								$('#dataGridComment').datagrid('reload');  
								
							}else{
								art.dialog.alert('删除失败，请联系管理员！');
							}
						}
					});
					
			    },
			    cancelVal: '取消',
			    cancel: true 
			});				
      	}
		
		//刷新评论
		function  reloadComments(){
			$('#dataGridComment').datagrid('reload');	
		}
						
		</script>
		
		<style>	  
			.notes {
			    padding: 5px;			  
			    color: #ccc;
			    background: #fffef7;
			    border: 1px solid #FBDA6D;
			}			
			.notes strong{	
				color:#bc9610;
			}
  
   	 </style>
   	 
	</head>
<body>
	<!--民意征集-->	
	<div style="float:left;-webkit-box-shadow:0 0 10px 5px #fafafa; -moz-box-shadow:0 0 10px 5px #fafafa; box-shadow:0 0 10px 5px #fafafa;  ">
		<table id="dataGridSolicit" width="100%" height="100%" type="dataGrid" data-options="toolbar:'#SolicitToolBar'"></table>	
		<div id="SolicitToolBar" style="height: auto;padding:0px;">
			<!--表单  搜索栏-->
			<div id="filter" class="module">					
				<ul>							
					<li>
						<label>标题：</label>
						<input type="text" value="" id="title" name="title"/>						
					</li>
					<li>
						<label>&nbsp;&nbsp;&nbsp;&nbsp;状态：</label>						
						<select id="status" class="datatype"  name="status">
							<option value="" selected="selected">请选择</option>							
							<option  value="1">&nbsp;&nbsp;&nbsp;&nbsp;等待生效</option>	
							<option  value="2">&nbsp;&nbsp;&nbsp;&nbsp;征集中&nbsp;&nbsp;</option>	
							<option  value="3">&nbsp;&nbsp;&nbsp;&nbsp;征集结束&nbsp;&nbsp;</option>
						</select>		
					</li>									
					<li>
						&nbsp;&nbsp;&nbsp;&nbsp;
						 <input id="visible" type="checkbox" name="visible" checked="checked" value="1"  style="width:10px;vertical-align:middle;" />
                	 	 <label for="visible" style="margin-right:8px;">网站显示</label>
					</li>
					<li><input type="button" class="btn btn-blue-h20-w2" value="查询" onclick="searchSolicitList()" /></li>
				</ul>
				<div class="clear"></div>
			</div>
			<!--表单  列表栏-->
			<div class="list module">
				<div class="hd">
					<h2 class="t">数据列表</h2>
					<span class="handle4filter" title="显示/隐藏查询条件"></span>
				</div>
				<div class="bd">
					<div id="toolbar">
						<ul id="buttonPlace">							
							<li>
								<a  href="javascript:addSolicit()" class="icon add" hideFocus="false">
									<span class = "glyphicon glyphicon-plus" style="display:in-line"></span>
									新增民意征集
								</a>
							</li>						
						</ul>
					</div>
				</div>
			</div>
		</div>		
		<div id="win"></div>		
	</div>
	
	<!--查看评论-->	
	<div id="roleGetComment" style="float:left;margin-left:5px;display:none;border: 1px solid #0092dc;border-radius: 5px;">
		<p class="notes"></p>	
		<table id="dataGridComment" type="dataGrid"	data-options="toolbar:'#CommentToolBar'">
		</table>		
		<div id="CommentToolBar" style="height: auto;padding:0px;">
			<!--表单  搜索栏-->
			<div id="filter" class="module">					
				<ul>				 
					<li>
						<input type="hidden" id="roleType" value="0"/>				
					</li>			
					<li>
						<label>评论内容：</label>
						<input type="text" value="" id="contents" name="contents"/>						
					</li>
					<li>
						<label>&nbsp;&nbsp;&nbsp;&nbsp;参与方式：</label>						
						<select id="typeId" class="datatype"  name="typeId">
							<option value="" selected="selected">请选择</option>							
							<option  value="0">&nbsp;&nbsp;&nbsp;&nbsp;点赞</option>	
							<option  value="1">&nbsp;&nbsp;&nbsp;&nbsp;评论&nbsp;&nbsp;</option>	
						</select>		
					</li>	
					<li>
						&nbsp;&nbsp;&nbsp;&nbsp;
						 <input id="is_publish" type="checkbox" name="is_publish" checked="checked" value="1"  style="width:10px;vertical-align:middle;" />
                	 	 <label for="is_publish" style="margin-right:8px;">公开</label>
					</li>				
					<li><input type="button" class="btn btn-blue-h20-w2" value="查询" onclick="searchSolicitComment()" /></li>
				</ul>
				<div class="clear"></div>
			</div>
			<!--表单  列表栏-->
			<div class="list module">
				<div class="hd">
					<h2 class="t">数据列表</h2>
					<span class="handle4filter" title="显示/隐藏查询条件"></span>
				</div>
				<div class="bd">
					<div id="toolbar">
						<ul id="buttonPlace">
							<li>
								<a  href="javascript:reloadComments()" class="icon add" hideFocus="false">
									<span class = "glyphicon glyphicon-refresh" style="display:in-line"></span>
									刷新
								</a>
							</li>													
						</ul>
					</div>
				</div>
			</div>
		</div>		
		<div id="win"></div>
	</div>


</body>
</html>